import Manager from './Manager'
import * as THREE from 'three'
import { OrbitControls } from "three/examples/jsm/controls/OrbitControls.js";
export default class Camera {
    cameraGroup = null;
    constructor() {
        this.manager = new Manager();
        this.sizes = this.manager.sizes;
        this.scene = this.manager.scene;
        this.canvas = this.manager.canvas;

        this.createCameraGroup();
        this.createPerspectiveCamera();
        // this.createOrthographicCamera();
        // this.createControls();
    }

    // 创建相机组 方便之后精准控制
    createCameraGroup() {
        this.cameraGroup = new THREE.Group();
        this.scene.add(this.cameraGroup);
    }
    // 透视相机
    createPerspectiveCamera() {
        this.perspectiveCamera = new THREE.PerspectiveCamera(
            35,
            this.sizes.aspect,
            0.1,
            1000
        )
        this.cameraGroup.add(this.perspectiveCamera)
        this.perspectiveCamera.position.z = 6
    }
    // 正交投影相机
    createOrthographicCamera() {
        this.frustrum = 5;

        this.orthographicCamera = new THREE.OrthographicCamera(
            (-this.sizes.aspect * this.frustrum) / 2,
            (this.sizes.aspect * this.frustrum) / 2,
            this.frustrum / 2,
            -this.frustrum / 2,
            -100,
            1000
        )
        this.cameraGroup.add(this.orthographicCamera)
    }
    // 相机控制器
    createControls() {
        this.controls = new OrbitControls(this.perspectiveCamera, this.canvas);
        this.controls.enableRotate = true; //旋转
        this.controls.enableZoom = true; //缩放
        this.controls.enableDamping = false; // 添加阻尼感
    }
    resize() {
        // 当页面尺寸变化 更新透视相机
        this.perspectiveCamera.aspect = this.sizes.aspect
        this.perspectiveCamera.updateProjectionMatrix();
        // 更新正交相机
        // this.orthographicCamera.left = (-this.sizes.aspect * this.frustrum) / 2
        // this.orthographicCamera.right = (this.sizes.aspect * this.frustrum) / 2
        // this.orthographicCamera.top = this.frustrum / 2
        // this.orthographicCamera.bottom = -this.frustrum / 2
        // this.orthographicCamera.updateProjectionMatrix();
    }

    update() {
        // this.controls.update();
    }
}